﻿using BLL;
using Easy.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Easy.Controllers
{
    public class AdminController : Controller
    {
        // GET: Admin 后台
        [AdminAuthentication]
        
        public ActionResult Index()
        {
            //清除session
            //Session Clear();
            return View();
        }
        //管理员登陆
        public ActionResult Login()
        {
            return View();
        }
        [HttpPost]
        public ActionResult Login(string adminName, string pwd)
        {
            //if (ModelState.IsValid)
            {
                // using (EasyDBEntities db=new EasyDBEntities())
                // {
                // admin admin = db.admin.FirstOrDefault(t => t.adminName == UserName && t.Pwd == Pwd);
                // if (admin!=null)
                // {
                //验证登陆
                //MyAuthentication.SerCookie(admin.adminName, admin.adminId.ToString(), "admin");
                // return RedirectToAction("Index");
                //、 }
                //   ModelState.AddModelError("","账号或密码错误");
                // }
                //}
                if (adminManager.CheckLogin(adminName, pwd))
                {
                    Session["adminName"] = adminName;
                    return RedirectToAction("Login");
                }
                return View();
            }
        }
        //退出
        public ActionResult Logout()
        {
            MyAuthentication.Logout();//退出
            return RedirectToAction("Index");
        }
    }
}